
package com.borqs.music.util;

import static com.borqs.music.util.MusicConf.ReqType.*;

import com.borqs.music.ui.DevConfigActivity;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;

public class MusicConf {
    private static final Map<String, String> typeMap = new HashMap<String, String>();

    // load configuration
    public static void updateServerURL(Context context){
        //String server = "http://apptest0.borqs.com/music";
        //String server = DevConfigActivity.getServerUrl();
        String server = BpcApiUtils.getServerURL(context, BpcApiUtils.KEY_FOR_MUSIC_SERVER);
        if (!server.endsWith("/")) {
            server = server + "/";
        }

        updateServerMap(server);

        String apiServerUrl = BpcApiUtils.getServerURL(context, BpcApiUtils.KEY_FOR_API_SERVER);
        if (!apiServerUrl.endsWith("/")) {
            apiServerUrl = apiServerUrl + "/";
        }
        typeMap.put(API_CREATE_STREAM, apiServerUrl + "post/create");
        typeMap.put(API_QUERY_VERSION, apiServerUrl + "qiupu/sync");
    }

    public static String getUrl(String requestType) {
        return typeMap.get(requestType);
    }

    public static void setServerUrl(String server) {
        if (server == null) {
            throw new IllegalArgumentException("Shouldn't be server = null");
        }

        String serverUrl = null;
        if (!server.endsWith("/")) {
            serverUrl = server + "/";
        } else {
            serverUrl = server;
        }

        updateServerMap(serverUrl);
    }

    private static void updateServerMap(String server) {
        typeMap.clear();
        typeMap.put(MUSIC_ALL, server + "music/all");
        typeMap.put(MUSIC_SEARCH_BY_SINGER, server + "music/songsofsinger");
        typeMap.put(MUSIC_INFO, server + "music/singlesong");
        typeMap.put(MUSIC_DOWNLOAD, server + "music/download");
        typeMap.put(MUSIC_SINGERS, server + "music/singers");
        typeMap.put(MUSIC_SEARCH_SONG, server + "music/search");
        typeMap.put(MUSIC_UPLOAD_SONG, server + "music/upload");
        typeMap.put(MUSIC_UPLOAD_LYRIC, server + "music/uploadlyric");
        typeMap.put(MUSIC_SONGS_SYNC, server + "music/checkandaddsongslink");
        typeMap.put(MUSIC_LYRIC_SYNC, server + "music/checklyric");
        typeMap.put(MUSIC_GET_LYRIC, server + "music/getlyric");
        typeMap.put(MUSIC_SEARCH_LYRIC, server + "music/searchlyric");
        typeMap.put(MUSIC_UPDATE_PRIVACY, server + "music/updatesongprivacy");
        typeMap.put(MUSIC_DELETE_SONG, server + "music/delsongsofuser");
        typeMap.put(MUSIC_HOT_SEARCH, server + "music/hotsearch");
        typeMap.put(MUSIC_SINGER_AREA, server + "music/areas");
        typeMap.put(MUSIC_UPDATE_ONLINE_FAVOR, server + "music/updateonlinefavor");
        typeMap.put(MUSIC_UPDATE_LOCAL_FAVOR, server + "music/updatelocalfavor");
        typeMap.put(MUSIC_SONG_OF_USER, server + "music/getsongsofuser");
        typeMap.put(MUSIC_ALBUM_OF_USER, server + "music/albumsofuser");
        typeMap.put(MUSIC_SINGER_OF_USER, server + "music/singersofuser");
        typeMap.put(MUSIC_COUNT_OF_USER_SONG, server + "music/getsongscountofuser");
        typeMap.put(MUSIC_SET_SETTINGS, server + "music/updatesetting");
        typeMap.put(MUSIC_GET_SETTINGS, server + "music/getsetting");
        typeMap.put(MUSIC_UPLOAD_STATISTICS, server + "music/statistic");
        typeMap.put(MUSIC_MY_SONGS, server + "music/mysongs");
    }

    public static interface ReqType {
        public static final String MUSIC_ALL = "music/all";
        public static final String MUSIC_SEARCH_BY_SINGER = "music/songsofsinger";
        public static final String MUSIC_INFO = "music/singlesong";
        public static final String MUSIC_DOWNLOAD = "music/download";
        public static final String MUSIC_SINGERS = "music/singers";
        public static final String MUSIC_SEARCH_SONG = "music/search";
        public static final String MUSIC_UPLOAD_SONG = "music/upload";
        public static final String MUSIC_UPLOAD_LYRIC = "music/uploadlyric";
        public static final String MUSIC_SONGS_SYNC = "music/checkandaddsongslink";
        public static final String MUSIC_LYRIC_SYNC = "music/checklyric";
        public static final String MUSIC_GET_LYRIC = "music/getlyric";
        public static final String MUSIC_SEARCH_LYRIC = "music/searchlyric";
        @Deprecated
        public static final String MUSIC_UPDATE_PRIVACY = "music/updatesongprivacy";
        public static final String MUSIC_DELETE_SONG = "music/delsongsofuser";
        public static final String MUSIC_MY_SONGS = "music/mysongs";
        public static final String MUSIC_HOT_SEARCH = "music/hotsearch";
        public static final String MUSIC_SINGER_AREA = "music/areas";
        public static final String MUSIC_UPDATE_ONLINE_FAVOR = "music/updateonlinefavor";
        public static final String MUSIC_UPDATE_LOCAL_FAVOR = "music/updatelocalfavor";
        public static final String MUSIC_SONG_OF_USER = "music/getsongsofuser";
        public static final String MUSIC_ALBUM_OF_USER = "music/albumsofuser";
        public static final String MUSIC_SINGER_OF_USER = "music/singersofuser";
        public static final String MUSIC_COUNT_OF_USER_SONG = "music/getsongscountofuser";
        public static final String MUSIC_SET_SETTINGS = "music/updatesetting";
        public static final String MUSIC_GET_SETTINGS = "music/getsetting";
        public static final String MUSIC_UPLOAD_STATISTICS = "music/statistic";

        public static final String API_CREATE_STREAM = "post/create";
        public static final String API_QUERY_VERSION = "qiupu/sync";
    }

    public static interface ReqParam {
        public static final String TICKET = "ticket";
        public static final String USERID = "userid";
        public static final String PAGE = "page";
        public static final String SORT = "sort";
        public static final String COUNT = "count";
        public static final String ISFULL = "isfull";
        public static final String PRIVACY = "privacy";
        public static final String KEYWORDS = "value";
        public static final String AREA = "area";
        public static final String SINGER = "singer";
        public static final String TITLE = "title";
    }

    public static interface SettingKeys {
        public static final String KEY_AUTO_UPLOAD_SONGS = "auto_upload_songs";
        public static final String KEY_AUTO_UPLOAD_FAVORITES = "auto_upload_favorites";
        public static final String KEY_DOWNLOAD_SONG_WHEN_PLAYING = "download_song_when_playing";
        public static final String KEY_MUSIC_SHARE_PRAVICY = "music_share_pravicy";
        public static final String KEY_SHOW_DOWNLOADING_SONGS = "show_downloading_songs";
        public static final String KEY_UPLOAD_SONGS_NOW = "auto_upload_songs_now";
    }

    public static interface UploadKeys {
        public static final String KEY_NEED_UPLOAD_LYRICS = "need_upload_lyrics";
        public static final String KEY_NEED_UPLOAD_STATISTICS = "need_upload_statistics";
        public static final String KEY_LAST_UPLOAD_LYRICS_TIME = "last_upload_lyrics_time";
        public static final String KEY_LAST_UPLOAD_STATISTICS_TIME = "last_upload_statistics_time";
    }

    public static interface ServerSettingNames {
        public static final String PRIVACY = "privacy";
    }
}
